home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume12 / psf2 / part04 < prev    next >
Encoding:
Text File  |  1990-05-19  |  39.8 KB  |  1,655 lines

  1. Newsgroups: comp.sources.misc
  2. From: tony@ajfcal.UUCP (Tony Field)
  3. subject: v12i107: psf2.0 source 4/6
  4. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5.  
  6. Posting-number: Volume 12, Issue 107
  7. Submitted-by: tony@ajfcal.UUCP (Tony Field)
  8. Archive-name: psf2/part04
  9.  
  10. psf2.0 source 4/6
  11. =================
  12. #! /bin/sh
  13. # This is a shell archive.  Remove anything before this line, then unpack
  14. # it by saving it into a file and typing "sh file".  To overwrite existing
  15. # files, type "sh file -c".  You can also feed this as standard input via
  16. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  17. # will see the following message at the end:
  18. #        "End of archive 4 (of 6)."
  19. # Contents:  Install.unix psbanner.c psd.c table.c
  20. # Wrapped by ajf@trifid on Tue May 15 01:10:49 1990
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'Install.unix' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'Install.unix'\"
  24. else
  25. echo shar: Extracting \"'Install.unix'\" \(10530 characters\)
  26. sed "s/^X//" >'Install.unix' <<'END_OF_FILE'
  27. X:
  28. X#    Install psf filters on AT&T Unix 3.2.2  (install.unix)
  29. X#
  30. X# NOTE:  if a different version of unix is used, this script
  31. X#     may need modification.....
  32. X#
  33. X#    If AT&T Unix 3.2.2 is used and FACE is available, then
  34. X#    the FACE printer database can be updated if the
  35. X#    option "-f" is provided on the command line.  The -f 
  36. X#    should be used for both installation and removal of psf.
  37. X#
  38. X#        Install.unix -f
  39. X#
  40. X#    note:      this script records configuration parameters in
  41. X#        various ".cfg" files in the current directory.
  42. X#        it also expects some .cfg files to be created
  43. X#        by "selectdef".
  44. X
  45. XPATH=.:/bin:/usr/bin:/etc
  46. X
  47. X#   ----------------------------------------------
  48. X#   beginning of things that may need modification
  49. X
  50. X
  51. X#  Define the destination directory of the psf binaries and scripts
  52. X#  and the print spooler directory
  53. X
  54. XBINDIR="/usr/local/bin"
  55. XSPOOLDIR="/usr/spool/lp"
  56. X
  57. X#  Unix lp printer systems files...
  58. X#  The directory structure follows AT&T unix 3.2.2 conventions.
  59. X#  Other unix systems may be different.
  60. X#  If you are not using AT&T Unix with FACE installed, then
  61. X#  ignore the reference to DATABASE.
  62. X
  63. XDEFDIR="/usr/spool/lp/model/psfprint.def"
  64. XMODEL="$SPOOLDIR/model"
  65. XDATABASE="/usr/vmsys/admin/PS/PORTSET/database"
  66. X
  67. X#  Specify the man pages directory.  If you are using a system
  68. X#  without man pages, ignore these entires.
  69. X#
  70. X#  Xenix uses man directories that look like /usr/man/man.1
  71. X#  If your directories do NOT use the dot (e.g.  man1)
  72. X#  format, then remove the "." in the definitions below.
  73. X
  74. XMANDIR="/usr/man/man."
  75. XCATDIR="/usr/man/cat."
  76. XMANCHAP="1"
  77. X
  78. X#   ------------------------------------------
  79. X#   The following should not need modification
  80. X
  81. XDEFFILES="defs/*.def"
  82. XPAGESIZE="undefined"
  83. XPNAME="undefined"
  84. XMODELNAME="psf"
  85. X
  86. X#  Create an entry line that will go into the FACE printer
  87. X#  selection data base in $DATABASE  (for AT&T unix 3.2.2)
  88. X#  If the $DATABASE file does not exist, then the following
  89. X#  is ignored.
  90. X
  91. XPRINTERDBS="Postscript-PSF            435_table    psf    postscript    tabs ixon ixoff onlcr"
  92. XPRINTERID="Postscript-PSF"
  93. X
  94. Xcase ${1} in
  95. X-f)    ;;
  96. X*)    DATABASE="z9+notHeRe"
  97. X    ;;
  98. Xesac
  99. X
  100. X#   PSF distribution files
  101. X
  102. XBINARIES="psf pnf pmf psd psbanner psdetect"
  103. XMANS="psf.1 pnf.1 pmf.1 psd.1 psmbox.1 psman.1 psnroff.1"
  104. XDOCS="psf.doc pnf.doc pmf.doc psd.doc psmbox.doc psman.doc psnroff.doc"
  105. XSCRIPTS="psmbox psman psmandouble psnroff"
  106. X
  107. X#   See if the man-page directory really exists
  108. X
  109. XHAVEMAN=
  110. Xif test ! -d $MANDIR$MANCHAP
  111. Xthen
  112. X    MANCHAP="Not.Allowed"
  113. X    HAVEMAN="(missing directory)"
  114. Xfi
  115. X
  116. X#    get existing psf installation parameters
  117. X
  118. Xif test -f Pmanchap.cfg
  119. Xthen
  120. X    MANCHAP=`cat -s Pmanchap.cfg`
  121. Xfi
  122. X
  123. Xif test -f Pbindir.cfg
  124. Xthen
  125. X    BINDIR=`cat -s Pbindir.cfg`
  126. Xfi
  127. X
  128. Xif test -f PPagesize.cfg
  129. Xthen
  130. X    PAGESIZE=`cat -s Ppagesize.cfg`
  131. Xfi
  132. Xif test -f Ppsfprint.cfg
  133. Xthen
  134. X    PNAME=`cat -s Ppsfprint.cfg`
  135. Xfi
  136. X
  137. X# Define return values
  138. X
  139. X: ${OK=0} ${FAIL=1} ${STOP=10} ${HALT=11}
  140. X
  141. X    
  142. X# Print an error message
  143. Xerror() {
  144. X    echo "\nError: $*" >&2
  145. X    return 1
  146. X}
  147. X
  148. X# Prompt with mesg, return non-zero on q
  149. Xprompt() {
  150. X    while    echo "\n${mesg}or enter q to $quit: \c" >&2
  151. X    do    read cmd
  152. X        case $cmd in
  153. X        +x|-x)    set $cmd                    ;;
  154. X        Q|q)    return 1                    ;;
  155. X        !*)    eval `expr "$cmd" : "!\(.*\)"`            ;;
  156. X        "")    # If there is an argument use it as the default
  157. X            # else loop until 'cmd' is set
  158. X            [ "$1" ] && { 
  159. X                cmd=$1
  160. X                return 0
  161. X            }
  162. X            : continue
  163. X            ;;
  164. X        *)    return 0                    ;;
  165. X        esac
  166. X    done
  167. X}
  168. X
  169. X
  170. Xshowstats () {
  171. X    echo "\nPSF INSTALLATION OPTIONS SELECTED"
  172. X    echo "--------------------------------"
  173. X    echo "printer selected from:   $PNAME"
  174. X    echo "printer page size is:    $PAGESIZE"
  175. X    echo "psf default options:     $PSFOPT"
  176. X    echo "banner options:          $BANNEROPT"
  177. X    echo "binaries and scripts in: $BINDIR"
  178. X    echo "man pages in chapter:    $MANCHAP"
  179. X}
  180. X
  181. X#   Copy the psf binares and scripts to target binary directory 
  182. X
  183. Xcreateprinter () { 
  184. X    bdir="$BINDIR" 
  185. X    echo " "
  186. X    echo "Install PSF binaries and"
  187. X    ./query "   scripts in which directory [$bdir]? "
  188. X    read bdir
  189. X    case "$bdir" in
  190. X    '')    ;;
  191. X    *)    BINDIR="$bdir"
  192. X        ;;
  193. X    esac
  194. X    if test ! -d $BINDIR
  195. X    then
  196. X        echo "\nDirectory $BINDIR does not exist."
  197. X        echo "Create the directory and re-start the installation.\n"
  198. X        exit $FAIL
  199. X    fi
  200. X    echo "$BINDIR" > Pbindir.cfg
  201. X    cp $BINARIES $BINDIR
  202. X    cp $SCRIPTS  $BINDIR
  203. X    rm -f psf.model
  204. X    sed "s@BINARY@$BINDIR@g" psfunix.LP | sed "s@OPTIONS@$PSFOPT@g" \
  205. X        | sed "s@BANNER@$BANNEROPT@g" > psf.model
  206. X    chmod +rw psf.model
  207. X    echo "psf binaries and scripts have been copied to $BINDIR"
  208. X    showstats
  209. X    return 0
  210. X}
  211. X
  212. X
  213. X#   Copy the psf model and control files to the spool directory.
  214. X
  215. Xmovefiles () {
  216. X    cp psf.model $MODEL/$MODELNAME
  217. X    cp $PNAME $DEFDIR
  218. X    chown lp $MODEL/$MODELNAME $DEFDIR
  219. X    chgrp bin $MODEL/$MODELNAME $DEFDIR
  220. X
  221. X#    If the FACE printer database exits, add the user provided the
  222. X#    -u option, then add a postscript printer to the database
  223. X
  224. X
  225. X    if test -f $DATABASE 
  226. X    then
  227. X        echo "$PRINTERDBS" >> $DATABASE
  228. X        echo "FACE printer file $DATABASE",
  229. X        echo "    has been updated with a psf printer definition."
  230. X    fi
  231. X    echo "lp spooler files are copied to:"
  232. X    echo "    $MODEL/$MODELNAME"
  233. X    echo "    $DEFDIR"
  234. X    showstats
  235. X    return 0
  236. X}
  237. X
  238. X
  239. X#   Set up default page sizes for psf to be placed in the
  240. X#   lp spooling script files
  241. X
  242. Xgetsizes () {
  243. X    PAGESIZE=`cat -s Ppagesize.cfg`
  244. X    PNAME=`cat -s Ppsfprint.cfg`
  245. X    cp $PNAME psfprint.def
  246. X    case $PAGESIZE in
  247. X    DEFAULT)    PSFOPT= ;;
  248. X    *)        PSFOPT=`echo -g $PAGESIZE` ;;
  249. X    esac
  250. X    case $PAGESIZE in
  251. X    DEFAULT)    BANNEROPT= ;;
  252. X    *)        BANNEROPT=`echo -g $PAGESIZE` ;;
  253. X    esac
  254. X    return 0
  255. X}
  256. X
  257. Xreplaceprinter () { 
  258. X    selectdef $DEFFILES
  259. X    case $? in
  260. X    0)    ;;
  261. X    *)    return $?
  262. X    esac
  263. X    getsizes
  264. X    return 0
  265. X}
  266. X    
  267. X
  268. Xmanpages () { 
  269. X    echo "\nNormally, man pages are not installed in AT&T unix 3.2.* systems."
  270. X    echo "If you have an on-line man system using 'man', then you may proceed"
  271. X    echo "with the man page installation.  If you do not have the man system,"
  272. X    echo "then specify 'none' for the man page chapter..."    
  273. X    cdir="$MANCHAP"
  274. X    echo " "
  275. X    ./query "Which chapter should be used for the PSF man pages [$cdir]? "
  276. X    read cdir
  277. X    case "$cdir" in
  278. X    '')    ;;
  279. X    none)    return 0
  280. X        ;;
  281. X    *)    MANCHAP="$cdir"
  282. X        ;;
  283. X    esac
  284. X    if test ! -d $MANDIR$MANCHAP
  285. X    then
  286. X        echo "\nDirectory $MANDIR$MANCHAP does not exist."
  287. X        echo "Select a different directory or quit and create the"
  288. X        echo "desired directory.\n"
  289. X        return 0
  290. X    fi
  291. X
  292. X    cp  pmf.1 $MANDIR$MANCHAP/pmf.$MANCHAP
  293. X    cp  pnf.1 $MANDIR$MANCHAP/pnf.$MANCHAP
  294. X    cp  psf.1 $MANDIR$MANCHAP/psf.$MANCHAP
  295. X    cp  psd.1 $MANDIR$MANCHAP/psd.$MANCHAP
  296. X    cp  psman.1 $MANDIR$MANCHAP/psman.$MANCHAP
  297. X    cp  psnroff.1 $MANDIR$MANCHAP/psnroff.$MANCHAP
  298. X    cp  psmbox.1 $MANDIR$MANCHAP/psmbox.$MANCHAP
  299. X    man $MANCHAP pmf > /dev/null
  300. X    man $MANCHAP pnf > /dev/null
  301. X    man $MANCHAP psd > /dev/null
  302. X    man $MANCHAP psf > /dev/null
  303. X    man $MANCHAP psman > /dev/null
  304. X    man $MANCHAP psnroff > /dev/null
  305. X    man $MANCHAP psmbox > /dev/null
  306. X    echo "$MANCHAP" > Pmanchap.cfg
  307. X    echo "\nPSF man pages have been installed in $MANDIR$MANCHAP"
  308. X    return 0
  309. X}
  310. X
  311. X#   if the man-page directory exists print the manuals with
  312. X#   nroff output.  if it does not exist, print from the
  313. X#   pre-formatted print files (using psf, of course...)
  314. X#   If the man page directory exists, ASSUME that nroff also exists...
  315. X
  316. Xprintman () {
  317. X    if test ! -d $MANDIR$MANCHAP
  318. X    then
  319. X        psf -2l 66 $DOCS | lp
  320. X    else
  321. X    psnroff -man $MANS
  322. X    fi
  323. X    return 0
  324. X}
  325. X
  326. Xremoveall () {
  327. X    cdir="$MANCHAP"
  328. X    echo " "
  329. X    ./query "Remove PSF man pages from chapter [$cdir]? "
  330. X    read cdir
  331. X    case "$cdir" in
  332. X    '')    ;;
  333. X    *)    MANCHAP="$cdir"
  334. X        ;;
  335. X    esac
  336. X    if test ! -d $MANDIR$MANCHAP
  337. X    then
  338. X        echo "\nDirectory $MANDIR$MANCHAP does not exist."
  339. X        exit $FAIL
  340. X    fi
  341. X
  342. X    bdir="$BINDIR" 
  343. X    echo " "
  344. X    ./query "Remove PSF binaries+scripts from directory [$bdir]? "
  345. X    read bdir
  346. X    case "$bdir" in
  347. X    '')    ;;
  348. X    *)    BINDIR="$bdir"
  349. X        ;;
  350. X    esac
  351. X    if test ! -d $BINDIR
  352. X    then
  353. X        echo "\nDirectory $BINDIR does not exist."
  354. X        exit 1
  355. X    fi
  356. X
  357. X    rm -f  $MANDIR$MANCHAP/pmf.$MANCHAP
  358. X    rm -f  $MANDIR$MANCHAP/pnf.$MANCHAP
  359. X    rm -f  $MANDIR$MANCHAP/psf.$MANCHAP
  360. X    rm -f  $MANDIR$MANCHAP/psd.$MANCHAP
  361. X    rm -f  $MANDIR$MANCHAP/psman.$MANCHAP
  362. X    rm -f  $MANDIR$MANCHAP/psnroff.$MANCHAP
  363. X    rm -f  $MANDIR$MANCHAP/psmbox.$MANCHAP
  364. X
  365. X    rm -f  $CATDIR$MANCHAP/pmf.$MANCHAP
  366. X    rm -f  $CATDIR$MANCHAP/pnf.$MANCHAP
  367. X    rm -f  $CATDIR$MANCHAP/psf.$MANCHAP
  368. X    rm -f  $CATDIR$MANCHAP/psd.$MANCHAP
  369. X    rm -f  $CATDIR$MANCHAP/psman.$MANCHAP
  370. X    rm -f  $CATDIR$MANCHAP/psnroff.$MANCHAP
  371. X    rm -f  $CATDIR$MANCHAP/psmbox.$MANCHAP
  372. X
  373. X    thisdir=`pwd`
  374. X
  375. X    cd $BINDIR
  376. X    rm $BINARIES $SCRIPTS
  377. X
  378. X    cd $thisdir
  379. X    
  380. X    rm $MODEL/$MODELNAME
  381. X    rm $DEFDIR
  382. X
  383. X#    If the FACE printer database exits, remove the psf printer
  384. X#NOTE should test to ensure that the copy was OK
  385. X#^^^^
  386. X#    if test -f $PRINTERDBS
  387. X#    then
  388. X#        grep -v "$PRINTERID" $DATABASE > /tmp/Pdbs.Temp.Q
  389. X#        cp /tmp/Pdbs.Temp.Q $DATABASE
  390. X#    fi
  391. X    if test -f $DATABASE
  392. X    then
  393. X        grep "$PRINTERID" $DATABASE > /dev/null
  394. X        case $? in
  395. X        0)    echo "\nThe FACE printer data base file:"
  396. X            echo "    $DATABASE"
  397. X            echo "should be manually edited to remove the reference to the"
  398. X            echo "psf printer identified as $PRINTERID"        
  399. X            ;;
  400. X        *)    ;;
  401. X        esac
  402. X    fi
  403. X
  404. X    return 0
  405. X}
  406. X
  407. X
  408. X#
  409. X# main()
  410. X#
  411. Xecho "\n\tPSF: Postscript print filter installation\n"
  412. Xecho "Please ensure that the binary directory and other file references"
  413. Xecho "are consistent between this install script and the Makefile.\n"
  414. Xecho "NB: Install the printer with FACE and/or lpadmin befor printing manuals.\n"
  415. Xecho "Some of the following defaults (+) may be modified during installation.\n"
  416. Xecho "+ Binary directory:             $BINDIR"
  417. Xecho "  Spooling directory:           $SPOOLDIR"
  418. Xecho "  Printer model file:           $MODEL/$MODELNAME"
  419. Xecho "  Printer model name:           $MODELNAME"
  420. Xif test -f $DATABASE
  421. Xthen
  422. X    echo "  FACE printer database file:   $DATABASE"
  423. X    echo "  Printer title in FACE is:     $PRINTERID"
  424. Xfi
  425. X
  426. Xif test -d $MANDIR$MANCHAP
  427. Xthen
  428. X    echo "+ Man-page directory:           $MANDIR$MANCHAP"
  429. X    if test -d $CATDIR$MANCHAP
  430. X    then
  431. X        echo "                                $CATDIR$MANCHAP"
  432. X    fi
  433. Xfi
  434. X
  435. Xwhile  
  436. X  mesg="\t1. Select printer type,  make printer model files
  437. X    2. Move psf binaries and scripts to $BINDIR
  438. X    3. Move psf files to $SPOOLDIR
  439. X    4. Install man pages in $MANDIR$MANCHAP   $HAVEMAN
  440. X    5. Print man pages
  441. X    6. Remove psf software and files from binary and spool directories
  442. X
  443. XSelect an option "
  444. X  quit=quit
  445. Xdo
  446. X  prompt
  447. X  choice=$cmd
  448. X  quit="return to the previous menu"
  449. X  case $choice in
  450. X  1)    replaceprinter
  451. X    ;;
  452. X  2)    [ -r Ppagesize.cfg ] && [ -r Ppsfprint.cfg ] && [ -r $PNAME ] && createprinter
  453. X    ;;
  454. X  3)    movefiles
  455. X      ;;
  456. X  4)    manpages
  457. X    ;;
  458. X  5)      printman
  459. X      ;;
  460. X  6)    removeall
  461. X      ;;
  462. X  [qQ]) break ;;
  463. X  *)    error "unknown option: \"$choice\""
  464. X    ;;
  465. X  esac
  466. Xdone
  467. Xexit $OK
  468. END_OF_FILE
  469. if test 10530 -ne `wc -c <'Install.unix'`; then
  470.     echo shar: \"'Install.unix'\" unpacked with wrong size!
  471. fi
  472. chmod +x 'Install.unix'
  473. # end of 'Install.unix'
  474. fi
  475. if test -f 'psbanner.c' -a "${1}" != "-c" ; then 
  476.   echo shar: Will not clobber existing file \"'psbanner.c'\"
  477. else
  478. echo shar: Extracting \"'psbanner.c'\" \(7088 characters\)
  479. sed "s/^X//" >'psbanner.c' <<'END_OF_FILE'
  480. X/* ta=4 */
  481. X/****************************************************************************
  482. X*                p s b a n n e r . c        v 2.0                                *
  483. X*                                                                            *
  484. X*    Print a banner page on a postscript printer for Xenix 2.2.3                *
  485. X*                                                                            *
  486. X*    The generated print stream is NOT minimally conforming as per Red Book.    *
  487. X*                                                                            *
  488. X*    Tony Field.       tony@ajfcal                                              *
  489. X****************************************************************************/
  490. X
  491. X#include <stdio.h>
  492. X#include "patchlevel.h"
  493. X
  494. X
  495. X/*    setup paper dimensions                                    */
  496. X
  497. Xtypedef struct                     /*    measurement in point                    */
  498. X{    char    paper_name[60];        /*    name of paper size (for command line)    */
  499. X    char    paper_tray[200];    /*    postscript operator to select this tray    */
  500. X    int        width;                /*    portrait point width of paper            */
  501. X    int        height;                /*    portrait point height of paper            */
  502. X    int        lx, ly, ux, uy;
  503. X} measure;
  504. X
  505. Xmeasure    *p;        /*    working set of parameters  (points to something below)     */
  506. X
  507. X                /*    standard paper sizes in portrait layout.                 */
  508. X
  509. Xmeasure    page_types[30] =
  510. X{            {     "letter",
  511. X                "statusdict begin lettertray end",
  512. X                  612,   792,    18,    15,   593,   777
  513. X            },
  514. X            {     "legal",
  515. X                "statusdict begin legaltray end",
  516. X                  612,  1008,    18,    15,   593,   993
  517. X            },
  518. X            {    "a4",
  519. X                "statusdict begin a4tray end",
  520. X                  595,   842,    18,    15,   578,   827
  521. X            },
  522. X            {    "b5",
  523. X                "statusdict begin b5tray end",
  524. X                  516,   729,    18,    15,   497,   712
  525. X            },
  526. X            {    "",            /* end of paper list */
  527. X                "",
  528. X                 0, 0,  0,  0, 0, 0
  529. X            }
  530. X};
  531. X
  532. Xchar    slots[4][100] = 
  533. X{            "statusdict begin 1 setpapertray end",
  534. X            "statusdict begin 2 setpapertray end",
  535. X            "",
  536. X            ""
  537. X} ;
  538. Xint        nslots = 2;
  539. X
  540. Xint    X_INDENT    = 30;        /*    points                        */
  541. Xint Y_INDENT    = 30;
  542. Xint    BIG_POINT    = 60;        /* changes to point size automatically scale    */
  543. Xint MED_POINT    = 35;        /* the printout.                                */
  544. Xint    SMALL_POINT    = 15;
  545. Xint    UX, UY, DX, DY, MAX_X, MAX_Y;
  546. X
  547. X/*    The following arguments are received in the command line
  548. X    argvp[9] and argv[10] may be page size and paper tray specifications.
  549. X*/
  550. X
  551. X#define    Userid        argv[1]
  552. X#define    Name        argv[2]
  553. X#define    Requestid    argv[3]
  554. X#define    Printer        argv[4]
  555. X#define    Options        argv[5]
  556. X#define    Date        argv[6]
  557. X#define    Machineid    argv[7]
  558. X#define    Title        argv[8]
  559. X
  560. Xmain (argc, argv)
  561. Xint        argc;
  562. Xchar    *argv[];
  563. X{    int        x, y, c, i, set_paper_tray, set_paper_bin;
  564. X    char    line[200];
  565. X    FILE    *pdef;
  566. X    
  567. X    if ((pdef = fopen (PDEF, "r")) != NULL)
  568. X    {    nslots = 0;
  569. X        fgets (line, 199, pdef);
  570. X        for (i = 0;  i < 25;  i++)
  571. X        {    if (fgets (line, 199, pdef) == NULL)
  572. X                break;
  573. X            trim (line);
  574. X            if (strncmp (line, "*fonts", 6) == 0)
  575. X                break;
  576. X            strcpy (page_types[i].paper_name, line);
  577. X            if (fgets (page_types[i].paper_tray, 199, pdef) == NULL)
  578. X                bad_file();
  579. X            trim (page_types[i].paper_tray);
  580. X            if (fgets (line, 100, pdef) == NULL)
  581. X                bad_file();
  582. X            trim (line);
  583. X            sscanf (line, "%d%d%d%d%d%d",
  584. X                &page_types[i].width,
  585. X                &page_types[i].height,
  586. X                &page_types[i].lx,
  587. X                &page_types[i].ly,
  588. X                &page_types[i].ux,
  589. X                &page_types[i].uy);
  590. X
  591. X        }
  592. X        page_types[i].paper_name[0] = '\0';
  593. X
  594. X        while (fgets (line, 199, pdef) != NULL)
  595. X        {    if (strncmp (line, "*slots", 6) == 0)
  596. X            {    while (fgets (line, 90, pdef) != NULL)
  597. X                {    trim (line);
  598. X                    if (strncmp (line, "*eof", 4) == 0)
  599. X                        break;
  600. X                    if (*line)
  601. X                    {    strcpy (slots[nslots], line);
  602. X                        if (++nslots > 3)
  603. X                            break;
  604. X                    }
  605. X                }
  606. X            }
  607. X        }
  608. X        fclose (pdef);
  609. X    }
  610. X    
  611. X    MAX_X = page_types[0].width;
  612. X    MAX_Y = page_types[0].height;
  613. X    set_paper_bin = 0;
  614. X    set_paper_tray = -1;
  615. X    
  616. X    for (i = 9;  i < argc;  i++)
  617. X    {    c = argv[i][1];
  618. X        switch (c)
  619. X        {
  620. X        case 'b':
  621. X            if ((set_paper_bin = atoi (argv[i+1])) > nslots)
  622. X            {    fprintf (stderr, "paper bin greater than %d\n", nslots);
  623. X                exit (1);
  624. X            }
  625. X            i++;
  626. X            break;
  627. X
  628. X        case 'g':
  629. X            for (set_paper_tray = 0;  page_types[set_paper_tray].paper_name[0];  set_paper_tray++)
  630. X            {    if (compare (argv[i+1], page_types[set_paper_tray].paper_name) == 0)
  631. X                {    MAX_X = page_types[set_paper_tray].width;
  632. X                    MAX_Y = page_types[set_paper_tray].height;
  633. X                    break;
  634. X                }
  635. X            }
  636. X            if (page_types[set_paper_tray].paper_name[0] == '\0')
  637. X            {    fprintf (stderr, "Invalid paper size\n");
  638. X                exit (1);
  639. X            }
  640. X            i++;
  641. X            break;
  642. X
  643. X        default: ;
  644. X        }
  645. X    }
  646. X
  647. X    UX    =    X_INDENT;
  648. X    UY    =    (MAX_Y - Y_INDENT);
  649. X    DX    =    (MAX_X - 2 * X_INDENT);
  650. X    DY    =    (BIG_POINT * 3);
  651. X
  652. X    /*    center text used for userid and job title print  */
  653. X    
  654. X    send ("%!\n");
  655. X    send ("/ctext {     % center text:   string x y dx\n");
  656. X    send ("   2 div\n");
  657. X    send ("   /Dx exch def\n");
  658. X    send ("   /Yv exch def\n");
  659. X    send ("   /Xv exch def\n");
  660. X    send ("   dup stringwidth pop\n");
  661. X    send ("   2 div\n");
  662. X    send ("   Dx exch sub\n");
  663. X    send ("   Xv add\n");
  664. X    send ("   Yv moveto\n");
  665. X    send ("   show\n");
  666. X    send ("} def\n");
  667. X    send ("%%EndProlog\n");
  668. X
  669. X    send ("%%Page: ? 1\n");
  670. X    if (set_paper_bin)
  671. X        printf ("%s\n", slots[set_paper_bin-1]);
  672. X
  673. X    if (set_paper_tray >= 0)
  674. X        printf ("%s\n", page_types[set_paper_tray].paper_tray);
  675. X        
  676. X    send ("/pg save def\n");
  677. X
  678. X    /*    draw a box for the userid */
  679. X    
  680. X    printf ("newpath\n");
  681. X    printf ("%d %d moveto\n", UX,UY);
  682. X    printf ("%d %d rlineto\n", DX, 0);
  683. X    printf ("%d %d rlineto\n", 0, -DY);
  684. X    printf ("%d %d rlineto\n", -DX, 0);
  685. X    printf ("closepath\n");
  686. X    printf ("4 setlinewidth\n");
  687. X    printf ("stroke\n");
  688. X
  689. X    /*    center the userid and the job title */
  690. X    
  691. X    y = UY - DY / 2 - BIG_POINT / 2;
  692. X    printf ("/Helvetica-BoldOblique findfont %d scalefont setfont\n", BIG_POINT);
  693. X    printf ("(%s) %d %d %d ctext\n", Userid, X_INDENT, y, DX);
  694. X
  695. X    y = UY - (DY + MED_POINT * 3);
  696. X    printf ("/Helvetica-Bold findfont %d scalefont setfont\n", MED_POINT);
  697. X    printf ("(%s) %d %d %d ctext\n", Title, X_INDENT, y, DX);
  698. X
  699. X    /*    print other banner page parameters */
  700. X    
  701. X    x = X_INDENT;
  702. X    y -= (MED_POINT * 2);
  703. X    printf ("%d %d moveto\n", x,y);    
  704. X    sendnormal ("User:       ");
  705. X    sendbold (Name);
  706. X
  707. X    y -= SMALL_POINT + (SMALL_POINT / 2);
  708. X    printf ("%d %d moveto\n", x,y);    
  709. X    sendnormal ("Request ID: ");
  710. X    sendbold (Requestid);
  711. X    
  712. X    y -= SMALL_POINT + (SMALL_POINT / 2);
  713. X    printf ("%d %d moveto\n", x,y);    
  714. X    sendnormal ("Printer ID: ");
  715. X    sendbold (Printer);
  716. X    
  717. X    y -= SMALL_POINT + (SMALL_POINT / 2);
  718. X    printf ("%d %d moveto\n", x,y);    
  719. X    sendnormal ("Options:    ");
  720. X    sendbold (Options);
  721. X    
  722. X    y -= SMALL_POINT + (SMALL_POINT / 2);
  723. X    printf ("%d %d moveto\n", x,y);    
  724. X    sendnormal ("Date:       ");
  725. X    sendbold (Date);
  726. X    
  727. X    y -= SMALL_POINT + (SMALL_POINT / 2);
  728. X    printf ("%d %d moveto\n", x,y);    
  729. X    sendnormal ("Machine:    ");
  730. X    sendbold (Machineid);
  731. X
  732. X    send ("showpage pg restore\n");
  733. X    send ("%%Trailer\n");    
  734. X    exit (0);
  735. X}
  736. X
  737. Xsend (s)
  738. Xchar    *s;
  739. X{
  740. X    while (*s)
  741. X        putchar (*s++);
  742. X}
  743. X
  744. Xsendnormal (s)
  745. Xchar     *s;
  746. X{
  747. X    printf ("/Courier findfont %d scalefont setfont\n", SMALL_POINT);
  748. X    send ("(");
  749. X    send (s);
  750. X    send (")show\n");
  751. X}
  752. X
  753. Xsendbold (s)
  754. Xchar     *s;
  755. X{
  756. X    printf ("/Helvetica-Bold findfont %d scalefont setfont\n", SMALL_POINT);
  757. X    send ("(");
  758. X    send (s);
  759. X    send (")show\n");
  760. X}
  761. X
  762. Xtrim (s)
  763. Xchar    *s;
  764. X{
  765. X    while (*s)
  766. X    {    if (*s < ' ')
  767. X        {    *s = 0;
  768. X            break;
  769. X        }
  770. X        s++;
  771. X    }
  772. X}
  773. X
  774. Xbad_file()
  775. X{
  776. X    fprintf (stderr, "Bad %s file\n", PDEF);
  777. X    exit (1);
  778. X}
  779. X
  780. Xcompare (a,b)
  781. Xchar    *a, *b;
  782. X{    int    aa, bb;
  783. X
  784. X    while (*a  &&  *b)
  785. X    {    aa = *a++;
  786. X        bb = *b++;
  787. X        if (toupper (aa)  !=  toupper (bb))
  788. X            return (aa - bb);
  789. X    }
  790. X    return (0);
  791. X}
  792. X
  793. END_OF_FILE
  794. if test 7088 -ne `wc -c <'psbanner.c'`; then
  795.     echo shar: \"'psbanner.c'\" unpacked with wrong size!
  796. fi
  797. # end of 'psbanner.c'
  798. fi
  799. if test -f 'psd.c' -a "${1}" != "-c" ; then 
  800.   echo shar: Will not clobber existing file \"'psd.c'\"
  801. else
  802. echo shar: Extracting \"'psd.c'\" \(10733 characters\)
  803. sed "s/^X//" >'psd.c' <<'END_OF_FILE'
  804. X/* ta=4 */
  805. X
  806. X/****************************************************************************
  807. X*                p s d . c        v2.0                                        *
  808. X*                                                                            *
  809. X*    Filter a "single sided" document to become a "double sided document"    *
  810. X*                                                                            *
  811. X*    Tony Field.       tony@ajfcal                                              *
  812. X*                                                                            *
  813. X*    The basic algorithm for "print_book()"  was based on a routine written    *
  814. X*    by Tom Neff (tneff@well.uucp) named "book" which printed 5.5x8.5         *
  815. X*    double sided on an HP LaserJet.                                            *
  816. X****************************************************************************/
  817. X/*
  818. X    A number of comments could be made about psd:
  819. X        1. it does work.
  820. X        2. it could work a lot better
  821. X        3. output is minimally conforming to postscript
  822. X        4. input is "similar to" postscript
  823. X
  824. X    the psf-generated control information is assumed to be at the
  825. X    end of the postscript print file.  The postscript file must contain
  826. X    a line like:
  827. X                    %PsfPtr: 21118
  828. X                    
  829. X    If the %PsPtr line is missing, then the file is NOT a book format.
  830. X    The format of this information is described in function read_control().
  831. X                
  832. X    psd does little to normal double sided print other than to change
  833. X    the order in which the pages are printed.  It also adjusts the
  834. X    %%Pages: value to reflect the actual page count printed.
  835. X    
  836. X    psd re-inserts translation, rotation and scale information eliminated
  837. X    by psf if the double sided print is to make an 8.5x5.5 "book".
  838. X
  839. X    Of course, a bunch of "very ugly" logic is needed for the "book"
  840. X    format to re-insert the postscript for page control - but it does work...
  841. X*/
  842. X
  843. X#include <stdio.h>
  844. X#include <string.h>
  845. X
  846. X/*    If books are made by generating two print files with the -s side count
  847. X    then set SIDECOUNT = 0  (i.e. no alternate paper hopper is available.
  848. X    
  849. X    If books are made by switching to the alternate print hopper for
  850. X    the second side, then set SIDECOUNT = 3  (i.e. second hopper is available
  851. X*/
  852. X
  853. X#define    SIDECOUNT    0
  854. X
  855. X#define LONG_STR    1000
  856. X#define MAX_PAGE    1000
  857. X
  858. Xstatic int nsheets, nhalves;
  859. Xstatic int row;
  860. Xstatic int lpage, rpage;
  861. X
  862. Xchar    slots[4][100] = 
  863. X{            "statusdict begin 1 setpapertray end",
  864. X            "statusdict begin 2 setpapertray end",
  865. X            "",
  866. X            ""
  867. X} ;
  868. Xint        nslots = 2;
  869. X
  870. Xchar    line[LONG_STR + 1];
  871. Xchar    scale[100];
  872. Xint        max_frame;
  873. Xint        landscape;
  874. Xint        real_width;
  875. Xint        height;
  876. Xint        width;
  877. Xint     dx_home[4];
  878. Xint     dy_home[4];
  879. Xint        npage;
  880. Xlong    pg_loc[MAX_PAGE];
  881. Xlong    trailer_loc;
  882. Xint        phys_page;
  883. Xint        side;
  884. Xint        bookwork;
  885. Xint        alternate_tray = 0;
  886. Xint        second_side = 0;
  887. X
  888. XFILE    *input_fp;
  889. XFILE    *output_fp;
  890. X
  891. Xchar    *pgmname;
  892. X
  893. Xmain(argc, argv)
  894. Xint        argc;
  895. Xchar    *argv[];
  896. X{    int        c;
  897. X    extern char *optarg;
  898. X    extern int    optind;
  899. X    FILE    *pdef;
  900. X    
  901. X    side = SIDECOUNT;            /* print size 1, 2, or both = 3 */
  902. X    
  903. X    if ((pdef = fopen (PDEF, "r")) != NULL)
  904. X    {    nslots = 0;
  905. X        while (fgets (line, LONG_STR - 1, pdef) != NULL)
  906. X        {    trim (line);
  907. X            if (strncmp (line, "*slots", 6) == 0)
  908. X            {    while (fgets (line, 90, pdef) != NULL)
  909. X                {    trim (line);
  910. X                    if (strncmp (line, "*eof", 4) == 0)
  911. X                        break;
  912. X                    if (*line)
  913. X                    {
  914. X                        strcpy (slots[nslots], line);
  915. X                        if (++nslots > 3)
  916. X                            break;
  917. X                    }
  918. X                }
  919. X            }
  920. X        }
  921. X        fclose (pdef);
  922. X    }
  923. X
  924. X    pgmname = argv[0];
  925. X    if (argc > 1  && strcmp (argv[1], "-") == 0)
  926. X        usage ();
  927. X        
  928. X    while ((c = getopt(argc, argv, "123-")) != -1)
  929. X    {    switch (c)
  930. X        {
  931. X        case '1':
  932. X        case '2':
  933. X        case '3':
  934. X            side = c - '0';
  935. X            break;
  936. X
  937. X        default:
  938. X            usage ();
  939. X        }
  940. X    }
  941. X    if (side == 3  &&  nslots < 2)
  942. X    {    fprintf (stderr, "Cannot use -3: only one output tray\n");
  943. X        exit (1);
  944. X    }
  945. X    
  946. X    if (side <= 0  ||  side >= 4)
  947. X    {    fprintf (stderr, "Print side must be 1, 2, or 3\n");
  948. X        exit (1);
  949. X    }
  950. X    if (optind >= argc)
  951. X        usage ();
  952. X
  953. X    output_fp = stdout;
  954. X    
  955. X    if ((input_fp = fopen(argv[optind], "r")) == NULL)
  956. X    {
  957. X        fprintf(stderr, "%s: Error opening %s!\n", pgmname, argv[1]);
  958. X        exit (1);
  959. X    }
  960. X    read_control (input_fp);
  961. X    get_prologue ();
  962. X    if (bookwork)
  963. X        print_book ();
  964. X    else
  965. X        print_double ();
  966. X    get_trailer ();
  967. X    exit (0);
  968. X}
  969. X
  970. X/****************************************************************************
  971. X*    read_control()                                                            *
  972. X*    Read the control information at the end of the file for the page         *
  973. X*    dimensions and byte address of the start of each page.                    *
  974. X*    Each of the parameter lines is a comment with the form %Psfxxxx: yyyy    *
  975. X****************************************************************************/
  976. X
  977. Xread_control (fp)
  978. XFILE    *fp;
  979. X{    char    tail[100];
  980. X    int        i, j;
  981. X    long    atol(), psfloc;
  982. X    
  983. X    /*    %PsfPtr: xxx  --> xxx is the pointer to the first %Psf... line
  984. X        in the file.  Seek to the indicated byte position to begin
  985. X        reading the Psf generated information which looks like:
  986. X
  987. X                %%Trailer                            <--- (a)
  988. X                %%DocumentFonts: Courier
  989. X                %%Pages: 8
  990. X                %PsfScale: 0.63194 0.79558 scale    <--- (b)
  991. X                %PsfMargin: 2 1 612 769 626
  992. X                %PsfHome: 0 0 0
  993. X                %PsfHome: 1 626 0
  994. X                %PsfHome: 2 0 0
  995. X                %PsfHome: 3 0 0
  996. X                %PsfPg: 0 405            <--- byte offsets to page
  997. X                %PsfPg: 1 3885
  998. X                %PsfPg: 2 7023
  999. X                    ...
  1000. X                %PsfPg: 9999 21072        <--- points to (a) above
  1001. X                %PsfPtr: 21118            <--- points to (b) above
  1002. X                <ctrl/d>
  1003. X    */
  1004. X    fseek (fp, -50L, 2);
  1005. X    fread (tail, 50, 1, fp);
  1006. X    if ((i = tscan (tail, "%PsfPtr:")) == -1)
  1007. X    {    fprintf (stderr, "%s: File is not in psf book format\n", pgmname);
  1008. X        exit (1);
  1009. X    }
  1010. X    psfloc = atol (tail + i + 9);        /*    beginning  of psf information */
  1011. X    fseek (fp, psfloc, 0);
  1012. X    
  1013. X    fgets (scale, 99, fp);
  1014. X    strcpy (tail, scale + 11);            /* get rid of the %psf comment */
  1015. X    strcpy (scale, tail);
  1016. X
  1017. X    /*    fetch psf data.    */
  1018. X                                                        /*    %PsfMargin:    */
  1019. X    fscanf (fp, "%s %d %d %d %d %d", tail,
  1020. X                &max_frame, &landscape, &real_width, &height, &width);
  1021. X
  1022. X    bookwork = max_frame == 2  &&  landscape;
  1023. X    for (i = 0;  i < 4;  i++)                            /*    %PsfHome:    */
  1024. X        fscanf (fp, "%s %d %d %d",  tail, &j, &dx_home[i], &dy_home[i]);
  1025. X
  1026. X    npage = 0;                                            /*    %PsfPg:        */
  1027. X    while (fscanf (fp, "%s %d %ld", tail, &i, &pg_loc[npage]) == 3)
  1028. X    {
  1029. X        if (i == 9999)
  1030. X        {    trailer_loc = pg_loc[npage];
  1031. X            break;
  1032. X        }
  1033. X        npage++;
  1034. X    }
  1035. X    fseek (fp, 0L, 0);
  1036. X}
  1037. X
  1038. X/****************************************************************************
  1039. X*    get_prologue()                                                            *
  1040. X*    Read the prologue and pass it directly to the output                    *
  1041. X****************************************************************************/
  1042. X
  1043. Xget_prologue ()
  1044. X{
  1045. X    fgets (line, LONG_STR, input_fp);        /*    skip the psf header     */
  1046. X    fprintf (output_fp, "%%!PS-Adobe-\n");    /*    write a valid header    */
  1047. X    while (fgets (line, LONG_STR, input_fp) != NULL)
  1048. X    {    if (strncmp (line, "%%Page:", 7) == 0)
  1049. X            break;
  1050. X        fputs (line, output_fp);
  1051. X    }
  1052. X}
  1053. X
  1054. X/****************************************************************************
  1055. X*    get_trailer ()                                                            *
  1056. X*    Read the trailer and pass it to the output.  Modify the page count to    *
  1057. X*    reflect the number of physical pages printed.                            *
  1058. X*    Remove any reference to the %Psf... lines.                                *
  1059. X****************************************************************************/
  1060. X
  1061. Xget_trailer ()
  1062. X{
  1063. X    if (phys_page == 0  ||  (bookwork  &&  second_side))
  1064. X        fprintf (output_fp, "showpage pg restore\n");
  1065. X    if (alternate_tray == 2)
  1066. X        fprintf (output_fp, "%s\n", slots[0]);
  1067. X    fseek (input_fp, trailer_loc, 0);
  1068. X    while (fgets (line, LONG_STR, input_fp) != NULL)
  1069. X    {    if (strncmp (line, "%%Pages:", 8) == 0)
  1070. X            fprintf (output_fp, "%%%%Pages: %d\n", phys_page);
  1071. X        else if (strncmp (line, "%Psf", 4) != 0)
  1072. X            fputs (line, output_fp);
  1073. X    }
  1074. X}
  1075. X
  1076. X/****************************************************************************
  1077. X*    display_page()                                                            *
  1078. X*    Send all ouput that belongs to a specific page.  For 8.5x5.5 books,        *
  1079. X*    generate the scale, etc that was omitted by psf.  Also enable the        *
  1080. X*    alternate tray if it to be used.                                        *
  1081. X****************************************************************************/
  1082. X
  1083. Xdisplay_page  (pgno, n)
  1084. Xint pgno;
  1085. Xint    n;
  1086. X{    static need_showpage = 0;
  1087. X
  1088. X    fseek (input_fp, pg_loc[pgno], 0);
  1089. X    fgets (line, LONG_STR, input_fp);
  1090. X    if (n == 0)
  1091. X    {
  1092. X        if ((phys_page  &&  bookwork)  ||  need_showpage)
  1093. X            fprintf (output_fp, "showpage pg restore\n");
  1094. X
  1095. X        if (alternate_tray == 1)
  1096. X        {    alternate_tray = 2;
  1097. X            fprintf (output_fp, "%s\n", slots[1]);
  1098. X        }
  1099. X        fprintf (output_fp, "%%%%Page: ? %d\n", ++phys_page);
  1100. X        if ((bookwork  &&  max_frame == 2)  ||  pgno >= npage)
  1101. X        {    fprintf (output_fp, "/pg save def\n");
  1102. X        }
  1103. X        need_showpage = pgno >= npage;
  1104. X    }
  1105. X
  1106. X    if (bookwork)
  1107. X    {    if (n == 0)
  1108. X        {
  1109. X            fprintf (output_fp, "90 rotate 0 %d translate\n", -real_width);
  1110. X            fprintf (output_fp, "%s", scale);
  1111. X        }
  1112. X        fprintf (output_fp, "%d %d translate\n", dx_home[n], dy_home[n]);
  1113. X    }
  1114. X
  1115. X    if (pgno < npage)
  1116. X    {    while (fgets (line, LONG_STR, input_fp) != NULL)
  1117. X        {    if(strncmp (line, "%%", 2) == 0)
  1118. X                break;
  1119. X            fputs (line, output_fp);
  1120. X        }
  1121. X    }
  1122. X}
  1123. X
  1124. X
  1125. X/****************************************************************************
  1126. X*    print_book()                                                            *
  1127. X*    print_book() is based on Tom Neff's (tneff@well.uucp) "book"             *
  1128. X*    for the HP LaserJet                                                     *
  1129. X*    Scan the text to ensure that the 8.5x.5.5 pages are constructed in        *
  1130. X*    such a way that a "book" is generated - simply staple in the middle    .    *
  1131. X****************************************************************************/
  1132. X
  1133. Xprint_book ()        
  1134. X{    int    done;
  1135. X
  1136. X    nsheets = (npage+3)/4;
  1137. X    nhalves = nsheets*4;
  1138. X    phys_page = 0;
  1139. X
  1140. X    if (side & 1)
  1141. X    {    for (rpage=0, lpage=nhalves-1;  rpage < lpage;  rpage+=2, lpage-=2)
  1142. X        {
  1143. X            display_page (lpage, 0);
  1144. X            display_page (rpage, 1);
  1145. X        }
  1146. X    }
  1147. X
  1148. X    if (side == 3)
  1149. X        alternate_tray = 1;
  1150. X
  1151. X    if ((side & 2)  &&  nhalves > 1)
  1152. X    {    second_side = 1;
  1153. X        for (rpage=nhalves/2, lpage=rpage-1; lpage >= 0; rpage+=2, lpage-=2)
  1154. X        {
  1155. X            display_page (lpage, 0);
  1156. X            display_page (rpage, 1);
  1157. X        }
  1158. X    }
  1159. X}
  1160. X
  1161. X/****************************************************************************
  1162. X*    print double()                                                            *
  1163. X*    print double sided pages.  first odd numbered, then even numbered.        *
  1164. X****************************************************************************/
  1165. X
  1166. Xprint_double()
  1167. X{
  1168. X    nsheets = (npage+1)/2;
  1169. X    phys_page = 0;
  1170. X
  1171. X    if (side & 1)
  1172. X    {    for (rpage=0;  rpage < nsheets;  rpage++)
  1173. X        {
  1174. X            display_page (rpage * 2, 0);
  1175. X        }
  1176. X    }
  1177. X
  1178. X    if (side == 3)
  1179. X        alternate_tray = 1;
  1180. X
  1181. X    if (side & 2  &&  npage > 1)
  1182. X    {    second_side = 1;
  1183. X        for (rpage=nsheets - 1;  rpage >= 0;  rpage--)
  1184. X        {
  1185. X            display_page (rpage * 2 + 1, 0);
  1186. X        }
  1187. X    }
  1188. X}
  1189. X
  1190. X
  1191. Xtscan (s, t)        /* search for string t in s */
  1192. Xchar     s[], t[];
  1193. X{
  1194. X    int    i, j, k;
  1195. X    for (i = 0;  s[i] != '\0';  i++)
  1196. X    {    for (j = i, k=0;  t[k] != '\0'  &&  s[j] == t[k];  j++, k++)
  1197. X            ;
  1198. X        if (t[k] == '\0')
  1199. X            return (i);
  1200. X    }
  1201. X    return (-1);
  1202. X}
  1203. Xusage ()
  1204. X{
  1205. X    printf ("Usage:  psd -n file\n");
  1206. X    printf ("  where:       n  = side number to print\n");
  1207. X    printf ("              -1 = print side 1 only\n");
  1208. X    printf ("              -2 = print side 2 only\n");
  1209. X    printf ("              -3 = print both sides in one pass\n");
  1210. X    printf ("           file   = print this file\n");
  1211. X    exit (0);
  1212. X}
  1213. X
  1214. Xtrim (s)
  1215. Xchar    *s;
  1216. X{
  1217. X    while (*s)
  1218. X    {    if (*s < ' ')
  1219. X        {    *s = 0;
  1220. X            break;
  1221. X        }
  1222. X        s++;
  1223. X    }
  1224. X}
  1225. END_OF_FILE
  1226. if test 10733 -ne `wc -c <'psd.c'`; then
  1227.     echo shar: \"'psd.c'\" unpacked with wrong size!
  1228. fi
  1229. # end of 'psd.c'
  1230. fi
  1231. if test -f 'table.c' -a "${1}" != "-c" ; then 
  1232.   echo shar: Will not clobber existing file \"'table.c'\"
  1233. else
  1234. echo shar: Extracting \"'table.c'\" \(8192 characters\)
  1235. sed "s/^X//" >'table.c' <<'END_OF_FILE'
  1236. X/* ta=4 */
  1237. X/************************************************************************
  1238. X*                    t a b l e . c                                        *
  1239. X*                                                                        *
  1240. X*    Generate the *.def tables required by psf to describe a printer        *
  1241. X*                                                                        *
  1242. X*    Scans the Adobe *.ppd files for specific parametric lines.            *
  1243. X************************************************************************/
  1244. X
  1245. X/*    Usage:    table files.ppd ...  destination.dir
  1246. X
  1247. X        where:    files.ppd are the various .ppd files to be converted.
  1248. X                destination.dir is the destination directory in which
  1249. X                    to place the generated .def file(s)
  1250. X        
  1251. X    The layout of the generated .def files is:
  1252. X
  1253. XNEC LC-890 v47.0 (modified)             <-- printer name for installpsf
  1254. X                                            (from *Nickname)
  1255. XLetter                                  <-- user name (e.g.   psf -g Letter)
  1256. X                                            (from *PageSize)
  1257. Xstatusdict begin lettertray end         <-- actual postscript to select size
  1258. X                                            (from *PageSize)
  1259. X  612   792    18    15   599   776     <-- page width page height LLx LLy URx URy
  1260. X                                              (page width/height from *PaperDimension)
  1261. X                                            (LLx LLy URx URy from *ImageableArea)
  1262. XLegal
  1263. Xstatusdict begin legaltray end
  1264. X  612  1008    18    19   593   990
  1265. XA4
  1266. Xstatusdict begin a4tray end
  1267. X  595   842    10     8   585   813
  1268. XB5
  1269. Xstatusdict begin b5tray end
  1270. X  516   729    18     7   482   702
  1271. X*fonts                                  <-- marker for fonts
  1272. XAvantGarde-Book                         <-- real font names in font dictionary
  1273. XAvantGarde-Demi                                (from *Font)
  1274. XBookman-Demi
  1275. XBookman-Light
  1276. XCourier
  1277. XHelvetica
  1278. XHelvetica-Narrow
  1279. XNewCenturySchlbk-Roman
  1280. XPalatino-Roman
  1281. XSymbol
  1282. XTimes-Roman
  1283. XZapfChancery-MediumItalic
  1284. XZapfDingbats
  1285. X*slots                                    <-- marker for paper tray select
  1286. Xstatusdict begin 1 setpapertray end     <-- select first tray
  1287. Xstatusdict begin 2 setpapertray end     <-- select second tray  etc..
  1288. X                                            (from *InputSlot)
  1289. X*eof                                    <-- logical end of file
  1290. X*/
  1291. X
  1292. X#include <stdio.h>
  1293. X#include <string.h>
  1294. X#include <sys/types.h>
  1295. X#include <sys/stat.h>
  1296. X
  1297. Xchar    nickname[200];
  1298. Xstruct pdef
  1299. X{
  1300. X    char    name[500];
  1301. X    char    set[500];
  1302. X    char    tray[500];
  1303. X    int        lx, ly, ux, uy, sx, sy;
  1304. X} ;
  1305. X
  1306. Xchar    *malloc();
  1307. Xchar    pname[100];
  1308. Xstruct pdef printer[40], pblank;
  1309. Xint        nprinter = 0;
  1310. Xchar    *fonts[100];
  1311. Xchar    *slots[10];
  1312. Xint        nfonts=0;
  1313. Xint        nslots=0;
  1314. X
  1315. Xmain (argc,argv)
  1316. Xint     argc;
  1317. Xchar    *argv[];
  1318. X{
  1319. X    char    *fname;
  1320. X    FILE    *fp_in, *fp_out;
  1321. X    int        i, j;
  1322. X    char    *c;
  1323. X    char    outname[100], fnonly[50];
  1324. X    char    *destdir;
  1325. X    
  1326. X    if (argc < 3)
  1327. X        usage ();
  1328. X
  1329. X    argc--;
  1330. X    destdir = argv[argc];
  1331. X    if (isdir (destdir) != 1)
  1332. X        usage ();
  1333. X
  1334. X    for (i = 1;  i < argc;  i++)
  1335. X    {    if ((fp_in = fopen (argv[i], "r")) != NULL)
  1336. X        {
  1337. X            for (j = 0;  j < nprinter;  j++)
  1338. X                printer[j] = pblank;
  1339. X            
  1340. X            for (j = 0;  j < nfonts;  j++)
  1341. X                free (fonts[j]);
  1342. X            
  1343. X            for (j = 0;  j < nslots;  j++)
  1344. X                free (slots[j]);
  1345. X            
  1346. X            nfonts = nslots = nprinter = 0;
  1347. X
  1348. X            fnameonly (argv[i], fnonly);
  1349. X            if ((c = strchr(fnonly, '.')))
  1350. X                *c = '\0';
  1351. X            strcpy (outname,destdir);
  1352. X            strcat (outname, "/");
  1353. X            strcat (outname, fnonly);
  1354. X            strcat (outname, ".def");
  1355. X
  1356. X            if ((fp_out = fopen (outname, "w")) == NULL)
  1357. X            {    fprintf (stderr, "%s: cannot create file %s\n", argv[0], outname);
  1358. X                exit (1);
  1359. X            }
  1360. X            build (fp_in);
  1361. X            display (fp_out);
  1362. X            fclose (fp_out);
  1363. X
  1364. X            fclose (fp_in);
  1365. X        }
  1366. X    }
  1367. X        
  1368. X}
  1369. X
  1370. Xbuild (fp_in)
  1371. XFILE    *fp_in;
  1372. X{
  1373. X    char    s[1000];
  1374. X    int        n;
  1375. X    int        a, b, c, d;
  1376. X    char    which[500];
  1377. X    
  1378. X    
  1379. X    while (fgets (s, 999, fp_in) != NULL)
  1380. X    {    trim (s);
  1381. X    
  1382. X        if (strncmp (s, "*PageSize", 9) == 0)
  1383. X        {
  1384. X            n = ptype (s, which);
  1385. X            gettext (s, printer[n].set);
  1386. X        }
  1387. X        else if (strncmp (s, "*NickName:", 10) == 0)
  1388. X        {
  1389. X            gettext (s, nickname);
  1390. X        }
  1391. X        else if (strncmp (s, "*Font ", 6) == 0)
  1392. X        {
  1393. X            ftype (s);
  1394. X        }
  1395. X        else if (strncmp (s, "*PaperTray", 10) == 0)
  1396. X        {
  1397. X            n = ptype (s, which);
  1398. X            gettext (s, printer[n].tray);
  1399. X        }
  1400. X        else if (strncmp (s, "*InputSlot", 10) == 0)
  1401. X        {
  1402. X            gettext (s, which);
  1403. X            slots[nslots] = malloc (strlen(which) + 2);
  1404. X            strcpy (slots[nslots], which);
  1405. X            nslots++;
  1406. X        }
  1407. X        else if (strncmp (s, "*ImageableArea", 14) == 0)
  1408. X        {
  1409. X            n = ptype (s, which);
  1410. X            sscanf (strchr (s, '"') + 1, "%d%d%d%d", &a, &b, &c, &d);
  1411. X            printer[n].lx = a;
  1412. X            printer[n].ly = b;
  1413. X            printer[n].ux = c;
  1414. X            printer[n].uy = d;
  1415. X        }
  1416. X        else if (strncmp (s, "*PaperDimension", 15) == 0)
  1417. X        {
  1418. X            n = ptype (s, which);
  1419. X            sscanf (strchr (s, '"') + 1, "%d %d", &a, &b);
  1420. X            printer[n].sx = a;
  1421. X            printer[n].sy = b;
  1422. X        }
  1423. X    }
  1424. X}
  1425. X
  1426. X
  1427. Xptype (s, which)
  1428. Xchar    *s, *which;
  1429. X{
  1430. X    char    *w, *ww;
  1431. X    int        i;
  1432. X
  1433. X    w = s;
  1434. X    while (*w++ != ' ')
  1435. X        ;
  1436. X    ww = which;
  1437. X    while (*w != ':')
  1438. X    {
  1439. X        if (*w == '/')
  1440. X        {
  1441. X
  1442. X            while (*w++ != ':')
  1443. X                ;
  1444. X            break;
  1445. X/*
  1446. X            ww = which;
  1447. X            w++;
  1448. X            continue;
  1449. X*/
  1450. X        }
  1451. X        if (*w == ' ')
  1452. X            *w = '-';
  1453. X        *ww++ = *w++;
  1454. X    }
  1455. X    *ww = '\0';
  1456. X    while (*w == ' ')
  1457. X        w++;
  1458. X/*
  1459. X    sscanf (s, "%*s%s", which);
  1460. X*/
  1461. X/*
  1462. X    w = which;
  1463. X    while (*w)
  1464. X    {    if (*w == ':')
  1465. X        {    *w = '\0';
  1466. X            break;
  1467. X        }
  1468. X        w++;
  1469. X    }
  1470. X*/
  1471. X    for (i = 0;  i < nprinter;  i++)
  1472. X    {    if (strcmp (which, printer[i].name) == 0)
  1473. X            return (i);
  1474. X    }
  1475. X    strcpy (printer[nprinter].name, which);
  1476. X    nprinter++;
  1477. X    return (nprinter - 1);
  1478. X}
  1479. X
  1480. Xftype (s)
  1481. Xchar    *s;
  1482. X{
  1483. X    char    *w, *ww;
  1484. X    char    which[100];
  1485. X    int        i;
  1486. X
  1487. X    w = s;
  1488. X    while (*w++ != ' ')
  1489. X        ;
  1490. X    ww = which;
  1491. X    while (*w != ':')
  1492. X    {
  1493. X        if (*w == ' ')
  1494. X            *w = '-';
  1495. X        *ww++ = *w++;
  1496. X    }
  1497. X    *ww = '\0';
  1498. X    while (*w == ' ')
  1499. X        w++;
  1500. X
  1501. X    if (strncmp (which, "Za", 2))
  1502. X    {    if (tscan (which, "Bold") >= 0   ||  tscan (which,"Italic") >= 0 
  1503. X            || tscan (which,"Obliq") >= 0)
  1504. X            return;
  1505. X    }
  1506. X    
  1507. X    fonts[nfonts] = malloc (strlen (which) + 1);
  1508. X    strcpy (fonts[nfonts++], which);
  1509. X    
  1510. X}
  1511. X
  1512. X
  1513. Xdisplay (fp_out)
  1514. XFILE    *fp_out;
  1515. X{
  1516. X    int        i;
  1517. X    
  1518. X    fprintf (fp_out, "%s\n", nickname);
  1519. X    for (i = 0;  i < nprinter;  i++)
  1520. X    {
  1521. X        fprintf (fp_out, "%s\n%s\n", printer[i].name, printer[i].set);
  1522. X        fprintf (fp_out, "%5d %5d %5d %5d %5d %5d\n",
  1523. X            printer[i].sx, printer[i].sy,
  1524. X            printer[i].lx, printer[i].ly, printer[i].ux, printer[i].uy);
  1525. X
  1526. X/*        print the actual size of the image area 
  1527. X
  1528. X        printf ("%-20s %-20s %4d %4d\n", pname, printer[i].name,
  1529. X            printer[i].ux - printer[i].lx + 1,
  1530. X            printer[i].uy - printer[i].ly + 1);
  1531. X*/
  1532. X    }
  1533. X
  1534. X    fprintf (fp_out, "*fonts\n");
  1535. X    for (i = 0;  i < nfonts;  i++)
  1536. X        fprintf (fp_out, "%s\n", fonts[i]);
  1537. X
  1538. X    fprintf (fp_out, "*slots\n");
  1539. X    for (i = 0;  i < nslots;  i++)
  1540. X        fprintf (fp_out, "%s\n", slots[i]);
  1541. X    fprintf (fp_out, "*eof\n");
  1542. X}
  1543. X
  1544. Xgettext (s, t)
  1545. Xchar    *s, *t;
  1546. X{
  1547. X    strcpy (t, strchr (s, '"') + 1);
  1548. X    while (*t)
  1549. X    {    if (*t == '"')
  1550. X        {    *t = '\0';
  1551. X            break;
  1552. X        }
  1553. X        t++;
  1554. X    }
  1555. X}
  1556. X
  1557. Xtscan (s, t)
  1558. Xchar     s[], t[];
  1559. X{
  1560. X    int    i, j, k;
  1561. X    for (i = 0;  s[i] != '\0';  i++)
  1562. X    {    for (j = i, k=0;  t[k] != '\0'  &&  s[j] == t[k];  j++, k++)
  1563. X            ;
  1564. X        if (t[k] == '\0')
  1565. X            return (i);
  1566. X    }
  1567. X    return (-1);
  1568. X}
  1569. X
  1570. Xtrim (s)
  1571. Xchar    *s;
  1572. X{
  1573. X    while (*s)
  1574. X    {    if (*s <  ' ')
  1575. X        {    *s = '\0';
  1576. X            break;
  1577. X        }
  1578. X        s++;
  1579. X    }
  1580. X}
  1581. X
  1582. X
  1583. Xfnameonly (path, fn)
  1584. Xchar    *path, *fn;
  1585. X{
  1586. X    char    *strrchr(), *where;
  1587. X    
  1588. X    if ((where = strrchr (path, '/')) == NULL)
  1589. X        strcpy (fn, path);
  1590. X    else
  1591. X        strcpy (fn, where + 1);
  1592. X    return;
  1593. X}
  1594. X
  1595. X
  1596. X/****************************************************************************
  1597. X*    isdir (name)                                                            *
  1598. X*                                                                            *
  1599. X*    See if the 'name' is a directory entry.  If so, return 1.  If not,        *
  1600. X*    return a 0.                                                                *
  1601. X*                                                                            *
  1602. X*    A call to stat() returns a bunch of parameters into 'buf' that             *
  1603. X*    essentially decodes the inode of the file into useful information.        *
  1604. X*    The st_node variable indicate the type of file.  Examine the stat.h        *
  1605. X*    file to see all possible file types.  For this routine, we are             *
  1606. X*    interested only in the bits S_IFMT (0170000 mask) of st_mode.  If these    *
  1607. X*    bits are S_IFDR (0040000), then we have a directory, otherwise not.        *
  1608. X****************************************************************************/
  1609. X
  1610. Xisdir (name)
  1611. Xchar    *name;
  1612. X{
  1613. X    struct stat buf;
  1614. X
  1615. X    if (stat (name, &buf) != 0)                /* ensure stat() is happy        */
  1616. X        return (-1);
  1617. X    if ((buf.st_mode & S_IFMT) == S_IFDIR)     /* good call, see if             */
  1618. X        return (1);                            /*        is directory            */
  1619. X    if ((buf.st_mode & S_IFMT) == S_IFREG)     /* good call, see if            */
  1620. X        return (0);                            /*        is file                    */
  1621. X    return (-1);                            /* something else                */
  1622. X}
  1623. X
  1624. Xusage ()
  1625. X{    fprintf (stderr, "Usage: table f.ppd f.ppd ... /dest.dir\n");
  1626. X    fprintf (stderr, "   where   f.ppd    = source .ppd files\n");
  1627. X    fprintf (stderr, "           dest.dir = desination directory for .def files\n");
  1628. X    exit (1);
  1629. X}            
  1630. X    
  1631. END_OF_FILE
  1632. if test 8192 -ne `wc -c <'table.c'`; then
  1633.     echo shar: \"'table.c'\" unpacked with wrong size!
  1634. fi
  1635. # end of 'table.c'
  1636. fi
  1637. echo shar: End of archive 4 \(of 6\).
  1638. cp /dev/null ark4isdone
  1639. MISSING=""
  1640. for I in 1 2 3 4 5 6 ; do
  1641.     if test ! -f ark${I}isdone ; then
  1642.     MISSING="${MISSING} ${I}"
  1643.     fi
  1644. done
  1645. if test "${MISSING}" = "" ; then
  1646.     echo You have unpacked all 6 archives.
  1647.     rm -f ark[1-9]isdone
  1648. else
  1649.     echo You still need to unpack the following archives:
  1650.     echo "        " ${MISSING}
  1651. fi
  1652. ##  End of shell archive.
  1653. exit 0
  1654.  
  1655.